package com.kkb.cubemall.order.config;

import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 数据源代理
 * @author wangzhongxiang
 */
@Configuration
public class SeataDataSourceConfig {

    // 注入dataSourceproperties
    @Autowired
    DataSourceProperties dataSourceProperties;

    @Bean
    public DataSource getDataSource(DataSourceProperties dataSourceProperties){
        // 获取到了druid数据源对象
        DruidDataSource dataSource = dataSourceProperties
                .initializeDataSourceBuilder()
                .type(DruidDataSource.class)
                .build();
        return new DataSourceProxy(dataSource);
    }


}